package com.janko.springbootbase.controller;

import com.janko.springbootbase.config.filter.MyHttpSessionListener;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

@RestController
public class MainController {

    @RequestMapping("/login")
    public String login(HttpServletRequest request) {
        HttpSession session = request.getSession(true);
        session.setAttribute("loginName", request.getParameter("name"));
        return "login";
    }

    /**
     * 查询当前在线人数
     * @return
     */
    @RequestMapping("online")
    @ResponseBody
    public String online() {
        return "当前在线人数：" + MyHttpSessionListener.online + "人";
    }
}
